package cn.deepmax.spring.cloud.system.mall.controller;

import cn.deepmax.spring.cloud.common.web.AjaxResponse;
import cn.deepmax.spring.cloud.system.mall.service.RemoteService;
import cn.deepmax.spring.cloud.system.mall.vo.Product;
import cn.deepmax.spring.cloud.system.mall.vo.User;
import cn.deepmax.spring.cloud.system.mall.vo.UserProductVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
public class MainController {

    @Autowired
    private RemoteService remoteService;


    @GetMapping("/agg.json")
    public AjaxResponse agg(@RequestParam Long userId, @RequestParam Long productId){
        log.info("get request {}:{}",userId, productId);
        User user = remoteService.getUser(userId);
        Product product = remoteService.getProduct(productId);
        UserProductVO vo = new UserProductVO();
        vo.setUser(user);
        vo.setProduct(product);
        return AjaxResponse.ok(vo);
    }
}
